var t, a = require("../../@babel/runtime/helpers/toConsumableArray"), e = require("../../@babel/runtime/helpers/defineProperty"), i = getApp().globalData.api, o = getApp(), s = require("../../utils/util.js");

Page({
    data: (t = {
        ceshi: wx.getAccountInfoSync().miniProgram.envVersion,
        isViewMove: !1,
        lastCity: "",
        lastCityAreaCode: null,
        activyshow: !0,
        ifUserGet: !0,
        activityEnd: !0,
        testName: getApp().globalData.testName,
        scrollNum: 0,
        animationData: {},
        menuList: [ {
            id: 1,
            img: "/image/home/home_menu_tjyy.png",
            title: "体检医院",
            url: "/pages/hospital-list/hospital-list",
            isJumpPkgList: !1,
            isJumpHospitalList: !0
        }, {
            id: 2,
            img: "/image/home/home_menu_tjtc.png",
            title: "体检套餐",
            url: "/pages/packagelists/packagelists",
            isJumpPkgList: !0,
            requestParamsUrl: ""
        },
        //  {
        //     id: 3,
        //     img: "/image/home/home_menu_qytj.png",
        //     title: "企业体检",
        //     url: "/subpackages/group/pages/group_team"
        // }, 
        {
            id: 9,
            img: "/image/home/home_menu_qytj.png",
            title: "职业健康",
            url: "/pages/packagelists/packagelists",
            isJumpPkgList: !0,
            requestParamsUrl: "t126"
        },
        
        {
            id: 4,
            img: "/image/home/home_munu_tjbg.png",
            title: "体检报告",
            url: "/subpackages/user-report/pages/dubaogao/dubaogao1"
        }, {
            id: 5,
            img: "/image/home/home_menu_jgrz.png",
            title: "咨询客服",
            url: "/subpackages/online/pages/kf-online1"
        }, {
            id: 5,
            img: "/image/home/home_menu_jgrz.png",
            title: "机构入驻",
            url: "/subpackages/jgrz/pages/jgrz"
        }, {
            id: 6,
            img: "/image/home/home_menu_rztj.png",
            title: "入职体检",
            url: "/pages/packagelists/packagelists",
            isJumpPkgList: !0,
            requestParamsUrl: "t40"
        },  {
            id: 8,
            img: "/image/home/home_menu_qstj.png",
            title: "全身体检222",
            url: "/pages/packagelists/packagelists",
            isJumpPkgList: !0,
            requestParamsUrl: "t91"
        },  {
            id: 10,
            img: "/image/home/home_menu_gdtj.png",
            title: "高端体检",
            url: "/pages/packagelists/packagelists",
            isJumpPkgList: !0,
            requestParamsUrl: "t65"
        } ],
        banner: null,
        notice: null,
        orderTjIndex: 0,
        menuListquick: [ null, null, null, null, null ],
        activyUrl: "",
        isReload: !1,
        hospitalListData: [],
        loadingExit: !1,
        fliterIsFloat: !1,
        filterindex: -1,
        id: "",
        classArray: [],
        screeningArray: [],
        tagsList: [],
        filterList: [],
        branchDataList: [],
        showBranch: !1,
        isShowOrderTj: !0
    }, e(t, "orderTjIndex", 0), e(t, "redEnvelopeList", []), e(t, "searchData", []), 
    e(t, "searchHistoryList", []), e(t, "ceshi", !1), e(t, "yxHosList", []), e(t, "yxHosIdList", []), 
    e(t, "showCoupon", !1), e(t, "showSuccess", !1), e(t, "showXslq", !1), t),
    onLoad: function(t) {
        console.log(t);
        var a = t.gdt_vid;
        a && (getApp().globalData.gdt_vid = a, this.setData({
            gdt_vid: a
        })), 
        this.getWinInfo(), 
        this.setData({
            listHeight: wx.getSystemInfoSync().windowHeight,
            lastCity: wx.getStorageSync("localCity") || o.globalData.selectedCity,
            lastCityAreaCode: wx.getStorageSync("localCityAreaCode") || o.globalData.selectedCityAreaCode,
            isLogin: !!wx.getStorageSync("token")
        });
        var e = this;
        this.getHeight(), this.getHomeData(), o.globalData.isFirstLoacation && (o.globalData.isFirstLoacation = !1, 
        o.firstLocation().then(function(t) {
            null != t && (console.log(t, o.globalData.selectedCity), t.city != o.globalData.selectedCity && e.getCityCode(t.province, t.city, t.latitude, t.longitude));
        }));
    },
    getHomeData: function() {
        this.goTopw(), this.getBannerDataw(), 
        this.getmenuDataw(), 
        // this.getyxhosw(), 
        this.loadHospitalData();
    },
    getBannerDataw: function() {
        var t = this, a = {
                        rest: getApp().globalData.selectedCityAreaCode,
                        openid:222,
            source: ''

        };
        i.post1("wechat/home/findHomeInfoDataByAreaCode", a, !this.data.banner).then(function(a) {
            if ("SUCCESS" == a.result) {
                var e = a.values, i = a.values.notice;
                t.setData({
                    banner: e,
                    orderTjIndex: 0,
                    notice: i || null
                });
            }
        });
    },
    getmenuDataw: function() {
        var t = this, a = {
            areacode: getApp().globalData.selectedCityAreaCode,
            commendType: "6Z03"
        };
        i.post1("/wechat/home/_listCommendPkgCateByCriteria", a, !0).then(function(a) {
            a.values = a.values.map(function(t) {
                return t.isJumpPkgList = !0, t.url = "/pages/packagelists/packagelists", t;
            }), t.setData({
                menuListquick: a.values
            });
        });
    },
    getWinInfo: function() {
        var t, a = wx.getSystemInfoSync(), i = wx.getMenuButtonBoundingClientRect(), o = 2 * (i.top - a.statusBarHeight) + i.height;
        this.setData((e(t = {}, "windowInfo.height", a.windowHeight), e(t, "windowInfo.width", a.windowWidth), 
        e(t, "windowInfo.statusBarHeight", a.statusBarHeight), e(t, "windowInfo.navHeight", o), 
        e(t, "windowInfo.bottomSafeViewHeight", a.safeArea.bottom - a.safeArea.height), 
        e(t, "windowInfo.statusBarHeight", a.statusBarHeight), e(t, "windowInfo.safeArraTop", a.safeArea.top), 
        e(t, "windowInfo.navTitleWidth", a.windowWidth - 2 * (a.windowWidth - i.left)), 
        e(t, "windowInfo.pdRight", a.windowWidth - i.left), t));
    },
    getyxhosw: function() {
        var t = this, a = {
            areacode: o.globalData.selectedCityAreaCode,
            lat: o.globalData.localLatitude || "",
            lon: o.globalData.localLongitude || ""
        };
        i.postPort("findHomeRecommendHosList", a).then(function(a) {
            if ("SUCCESS" == a.result) {
                var e, i = [];
                e = a.values, a.values.forEach(function(t) {
                    i.push(t.id);
                }), t.setData({
                    yxHosList: e,
                    yxHosIdList: i
                });
            }
        });
    },
    getHeight: function() {
        var t = this;
        wx.getSystemInfo({
            success: function(a) {
                var e = a.windowHeight;
                t.setData({
                    clientHeight: e
                });
            }
        });
    },
    getCityCode: function(t, a, e, s) {
        var n = this, l = this, r = {
            province: t,
            city: a
        };
        i.post1("/wechat/home/getlocalcityinfo", r, !1).then(function(t) {
            if ("1" == t.code) {
                var i = t.data.areacode;
                o.globalData.localCity = a, o.globalData.localCityAreaCode = i, o.globalData.localLatitude = e, 
                o.globalData.localLongitude = s, o.globalData.selectedCity = a, o.globalData.selectedCityAreaCode = i, 
                l.setData({
                    lastCity: a,
                    lastCityAreaCode: i
                }, function() {
                    n.getHomeData();
                });
            }
        }, function(t) {});
    },
    goTopw: function() {
        wx.pageScrollTo({
            scrollTop: 0,
            duration: 300
        });
    },
    loadHospitalData: function() {
        this.getHospitalData(1);
    },
    loadMoreHospitalData: function() {
        this.data.loadingExit || this.getHospitalData(this.data.hospitalListData.pageNum + 1);
    },
    getHospitalData: function(t) {
        var e = this, s = this, n = "", l = "";
        console.log("sdf",e.data.filterList)
        0 == s.data.isReload ? (this.data.screeningArray.forEach(function(t, a) {
            e.data.filterList.forEach(function(a, e) {
                t.type == a.type && (a.selectId = t.selectId);
            });
        }), this.data.filterList.forEach(function(t, a) {
            0 != t.selectId && t.microCriteriaDTOList.forEach(function(a, e) {
                a.id == t.selectId && ("6B01" == a.type ? l = a.code : n += a.code);
            });
        })) : s.setData({
            isReload: !1
        });
        s.setData({
                isReload: !1
            });

        var searchModel1={
            areacode: o.globalData.selectedCityAreaCode,
            clientType: 2,
            lat: o.globalData.localLatitude || "",
            lon: o.globalData.localLongitude || "",
            oriFutureDate: "",
            name: "",
            originUnitParam: n,
            oriOrderBy: l
        };

        var r = {
            page: t,
            pageSize: 10,
            searchModel:JSON.stringify(searchModel1)
        };
        null != this.data.gdt_vid && (r.searchModel.clickId = this.data.gdt_vid),
         i.post1("/wechat/home/_listMicroHospital", r).then(function(t) {
            if ("1" == t.code) {
                var e = s.data.hospitalListData;
                1 == t.data.pageNum ? e = t.data : (e.list = [].concat(a(s.data.hospitalListData.list), a(t.data.list)), 
                e.pageNum = t.data.pageNum, e.total = t.data.total), s.setData({
                    loadingExit: e.list.length >= t.data.total,
                    hospitalListData: e,
                    tagsList: t.data.microBottomCriteriaListDTOS,
                    filterList: t.data.microCriteriaListDTOS
                });
                //  s.checkFilterDataw();
            }
        }, function(t) {});
    },
    checkFilterDataw: function() {
        var t = [], a = [], e = 0;
        this.data.filterList.forEach(function(i, o) {
            if (e < 3 && ("6B01" == i.type || "6B02" == i.type || "6B03" == i.type)) {
                var s = {
                    id: 0,
                    code: null,
                    name: "不限",
                    type: i.type,
                    value: null,
                    isShowBottom: !1,
                    orderBy: null,
                    classify: null,
                    showBottomOrderBy: null
                };
                "6B01" == i.type && (i.typeName = "推荐排序", s.name = "推荐排序");
                var n = i.microCriteriaDTOList;
                0 != n.length && n.unshift(s), 0 != i.selectId && n.forEach(function(t, a) {
                    i.selectId == t.id && (i.selectName = t.name);
                }), t.push(i), e += 1;
            } else i.showMore = !1, "6B07" != i.type && "6B08" != i.type && (i.microCriteriaDTOList = i.microCriteriaDTOList.filter(function(t) {
                if (t.ifShow) return t;
            }), a.push(i));
        });
        var i = this.data.tagsList;
        this.data.filterList.forEach(function(t, a) {
            0 != t.selectId && i.forEach(function(a, e) {
                t.selectId == a.id && t.type == a.type && (a.isSelect = 1);
            });
        }), this.setData({
            classArray: t,
            screeningArray: a,
            tagsList: i
        });
    },
    packageDetailTap: function(t) {
        var a = t.currentTarget.dataset.val, e = "";
        e = a.hasOwnProperty("sourceId") ? a.domain + "-combo-" + a.sourceId : a.id, wx.navigateTo({
            url: "/pages/packagedetails/packagedetails?requestParams=".concat(e, "&areacode=").concat(a.areacode)
        });
    },
    hospitalDetailTap: function(t) {
        wx.navigateTo({
            url: "/pages/hospitalinfo/hospitalinfo?domain=".concat(t.currentTarget.dataset.info.domain, "&areacode=").concat(t.currentTarget.dataset.info.areacode)
        });
    },
    yxHospitalDetailTap: function(t) {
        this.hospitalDetailTap(t);
    },
    yxPackageDetailTap: function(t) {
        this.packageDetailTap(t);
    },
    selectMenu: function(t) {
        var a = t.currentTarget.dataset.item;
        "企业体检" == a.title ? wx.navigateTo({
            url: "".concat(a.url, "?code=").concat(this.data.selectedAreaCode)
        }) : "体检报告" == a.title || "机构入驻" == a.title || "健康讲堂" == a.title || "咨询客服" == a.title ? wx.navigateTo({
            url: a.url
        }) : (1 == a.isJumpPkgList && (o.globalData.jumpPkgList.isJumpPkgList = a.isJumpPkgList, 
        o.globalData.jumpPkgList.requestParamsUrl = a.requestParamsUrl), 1 == a.isJumpHospitalList && (o.globalData.jumpHospitalList.isJumpHospitalList = a.isJumpHospitalList, 
        a.requestParamsUrl && (o.globalData.jumpHospitalList.requestParamsUrl = a.requestParamsUrl)), 
        wx.switchTab({
            url: a.url,
            success: function(t) {
                var a = getCurrentPages().pop();
                null != a && null != a && a.onLoad({});
            }
        })), "11" == a.id && wx.openCustomerServiceChat({
            extInfo: {
                url: "https://work.weixin.qq.com/kfid/kfc7b7e2d99e269adf4"
            },
            corpId: "wwd7544c3dc85d4ec3",
            success: function(t) {},
            fail: function(t) {}
        });
    },
    setFilterPanel: function(t) {
        var a = t.currentTarget.dataset.findex, e = this.data.filterindex;
        this.setData({
            filterindex: e == a ? -1 : a
        });
    },
    itemClassTap: function(t) {
        var a = t.currentTarget.dataset.iteminfo;
        this.hideFilter();
        var e = this.data.filterList;
        e.forEach(function(t, e) {
            t.type == a.type && (t.selectId = a.id);
        }), this.setData({
            filterList: e
        }), this.goHospitalListTop(), this.loadHospitalData();
    },
    rightTabMoreTap: function(t) {
        var a = t.currentTarget.dataset.idx, e = this.data.screeningArray;
        e.forEach(function(t, e) {
            a == e && (t.showMore = !t.showMore);
        }), this.setData({
            screeningArray: e,
            toView: "a" + a,
            screeningSelectIndex: a
        });
    },
    rightTabMenuItemTap: function(t) {
        var a = t.currentTarget.dataset.iteminfo, e = this.data.screeningArray;
        e.forEach(function(t, e) {
            a.type == t.type && (t.selectId == a.id ? t.selectId = 0 : t.selectId = a.id);
        }), this.setData({
            screeningArray: e
        });
    },
    hideFilter: function() {
        this.setData({
            filterindex: -1
        });
    },
    tagsTap: function(t) {
        var a = t.currentTarget.dataset.taginfo, e = this.data.filterList;
        e.forEach(function(t, e) {
            t.type == a.type && (0 == t.selectId || t.selectId != a.id ? t.selectId = a.id : t.selectId = 0);
        }), this.setData({
            filterList: e
        }), this.goHospitalListTop(), this.loadHospitalData();
    },
    hostpitalPackageTap: function(t) {
        var a = t.currentTarget.dataset.info;
        wx.navigateTo({
            url: "/pages/hospitalinfo/hospitalinfo?domain=".concat(a.domain, "&areaCode=").concat(a.areaCode, "&selectPkgId=").concat(a.id)
        });
    },
    branchTap: function(t) {
        this.closeBranchTap();
        var a = "/pages/hospitalinfo/hospitalinfo?domain=".concat(t.currentTarget.dataset.info.domain, "&areaCode=").concat(t.currentTarget.dataset.info.areaCode);
        wx.navigateTo({
            url: a
        });
    },
    hospitalBranchTap: function(t) {
        var a = t.currentTarget.dataset.info;
        this.getHospitalBranchDat(a.areaCode, a.groupId, a.id);
    },
    getHospitalBranchDat: function(t, a, e) {
        if (t || a) {
            var o = this, s = {
                pageNum: 1,
                pageSize: 50,
                searchModel: {
                    areaCode: t,
                    name: null,
                    hospitalGroupId: a
                }
            };
            i.postPort("listMicroBrandHospitalList", s, !1).then(function(t) {
                if ("SUCCESS" == t.result) {
                    var a = [];
                    t.values.list.forEach(function(t, i) {
                        t.id != e && a.push(t);
                    }), o.setData({
                        branchDataList: a,
                        showBranch: !0
                    });
                }
            }, function(t) {
                t.data.hasOwnProperty("result") && "ERROR" == t.data.result && wx.showToast({
                    title: t.data.message[0].message,
                    icon: "none",
                    duration: 2e3,
                    mask: !0
                });
            });
        }
    },
    closeBranchTap: function() {
        this.setData({
            showBranch: !1
        });
    },
    upgradeTap: function(t) {
        this.setData({
            isReload: !0
        }), this.goHospitalListTop(), this.loadHospitalData();
    },
    cleanTap: function() {
        var t = this.data.screeningArray;
        t.forEach(function(t, a) {
            t.selectId = 0;
        }), this.setData({
            screeningArray: t
        });
    },
    sureTap: function() {
        this.hideFilter(), this.goHospitalListTop(), this.loadHospitalData();
    },
    goHospitalListTop: function() {
        wx.createSelectorQuery().selectAll("#one,#three").boundingClientRect().exec(function(t) {
            console.log(t);
            var a = 0;
            t.length > 0 && t[0].forEach(function(t, e) {
                t.height && (a += t.height);
            }), wx.pageScrollTo({
                scrollTop: a,
                duration: 300,
                success: function() {}
            });
        });
    },
    orderTjClick: function() {
        var t = this.data.isShowOrderTj;
        this.setData({
            isShowOrderTj: !t
        });
    },
    rderTjChange: function(t) {
        this.setData({
            orderTjIndex: t.detail.current
        });
    },
    orderTjOrderClick: function(t) {
        wx.navigateTo({
            url: "/pages/usercenter/userOrder/order_particulars/order-particulars?orderId=".concat(t.currentTarget.dataset.orgid)
        });
    },
    hosMapClick: function(t) {
        var a = {
            domain: t.currentTarget.dataset.domain
        };
        i.getPort("getSimpleHosDTOByDomain", a, !0).then(function(t) {
            if ("SUCCESS" == t.result) {
                var a = t.values.lat, e = t.values.lon, i = t.values.address, o = t.values.name, n = s.convert2TecentMap(e, a);
                wx.openLocation({
                    latitude: n.lat,
                    longitude: n.lng,
                    name: o,
                    address: i
                });
            }
        }, function(t) {});
    },
    tjxzClick: function() {
        this.tixz = this.selectComponent("#tixz"), this.tixz.show();
    },
    onReachBottom: function() {
        0 == this.data.loadingExit && this.loadMoreHospitalData();
    },
    onPageScroll: function(t) {},
    touchStart: function() {
        this.setData({
            isViewMove: !0
        });
    },
    touchEnd: function() {
        var t = this;
        setTimeout(function() {
            t.setData({
                isViewMove: !1
            });
        }, 1e3);
    },
    onlineTap: function() {
        getApp().onlineKeFuTap({
            pagePath: "/pages/homepages/homepages"
        });
    },
    reminder: function(t) {
        wx.showToast({
            title: t,
            icon: "none",
            duration: 2e3,
            mask: !0
        });
    },
    onShow: function(t) {
        var a = this, e = !!wx.getStorageSync("token");
        (this.data.lastCity != o.globalData.selectedCity && this.data.lastCityAreaCode != o.globalData.selectedCityAreaCode || e != this.data.isLogin) && (this.setData({
            isLogin: e,
            isReload: !0,
            lastCity: o.globalData.selectedCity,
            lastCityAreaCode: o.globalData.selectedCityAreaCode
        })
        , this.getHomeData()
        
        ), setTimeout(function() {
            getApp().globalData.userInfo && a.data.testName.includes(getApp().globalData.userInfo.phone) && a.setData({
                ceshi: !0
            });
        }, 3e3);
    },
    onShareAppMessage: function() {
        if (!this.data.activityEnd) {
            return {
                title: this.data.getcoudetail.description,
                imageUrl: "2"
            };
        }
    }
});